﻿using System;
using System.Threading.Tasks;
using ABPLHQCS.Books;
using ABPLHQCS.FormItems;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using ABPLHQCS.Categories;

namespace ABPLHQCS;

public class ABPLHQCSDataSeederContributor
    : IDataSeedContributor, ITransientDependency
{
    private readonly IRepository<Book, Guid> _bookRepository;

   // private readonly IRepository<FormCategory, Guid> _FormCategoryRepository;

    public ABPLHQCSDataSeederContributor(IRepository<Book, Guid> bookRepository)
    {
        _bookRepository = bookRepository;
        //_FormCategoryRepository = formcategoryRepository;
    }

    public async Task SeedAsync(DataSeedContext context)
    {
        if (await _bookRepository.GetCountAsync() <= 0)
        {
            await _bookRepository.InsertAsync(
                new Book
                {
                    Name = "1984",
                    Type = BookType.Dystopia,
                    PublishDate = new DateTime(1949, 6, 8),
                    Price = 19.84f
                },
                autoSave: true
            );

            await _bookRepository.InsertAsync(
                new Book
                {
                    Name = "The Hitchhiker's Guide to the Galaxy",
                    Type = BookType.ScienceFiction,
                    PublishDate = new DateTime(1995, 9, 27),
                    Price = 42.0f
                },
                autoSave: true
            );
        }

        //if (await _FormCategoryRepository.GetCountAsync()<=0)
        //{
        //    await _FormCategoryRepository.InsertAsync(
        //        new FormCategory
        //        {   
        //            CategoryName = "质控表单",
        //            SortNum = 1
        //        }, autoSave: true
        //        );
        //}
    }
}